<?php


namespace app\admin\model;


use app\common\model\TimeModel;
use app\common\constants\MenuConstant;
use think\model\concern\SoftDelete;
class SystemApplet extends TimeModel
{   

    protected $name = 'system_applet';
   
    public function getNodeTreeList($checkNodeList)
    {
        $list = $this->field('id,pid,name as title')->select()->toArray();
      
        $list = $this->getTreeList($list,0,$checkNodeList);
        return $list;
    }

 

    public function getTreeList($array= array(),$pid=0,$checkNodeList)
    {
        $list = [];
        foreach ($array as &$value) {
            if ($value['pid']==$pid) {
                $value['checked']=false;
                if(in_array($value['id'],$checkNodeList)){
                    $value['checked']=true;
                }
                $value1=$value;
                
                $value1['children'] = $this->getTreeList($array, $value['id'],$checkNodeList);
                if ($value1['children'] == null) {
                    unset($value1['children']);
                }
                $list[]=$value1;
            }
        }
        return $list;
    }
    
}